package com.dream.prm.socket;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket入口
 * @author w.g
 * @date 2019-07-13
 * 
 */
@Component
@EnableWebMvc
@EnableWebSocket
public class MyWebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {

	@Resource
	private MyWebSocketHandler webSocketHandler;
	
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		// TODO Auto-generated method stub
		//WebSocket设置路由,当客户端发起websocket连接,就把/path交给handler处理
		//addInterceptors，为handler添加拦截器,可以在调用handler前后加入自己的逻辑代码
		registry.addHandler(webSocketHandler, "/wsMy").addInterceptors(new HandShake());
		registry.addHandler(webSocketHandler, "/wsMy/sockjs").addInterceptors(new HandShake()).withSockJS();
	}

}
